package ModelLayer;

import java.util.ArrayList;
/**
 * Write a description of class RentContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class RentContainer
{
    // instance variables - replace the example below with your own
    public ArrayList<Rent> rents;
    private Rent rent;

    /**
     * Constructor for objects of class RentContainer
     */
    public RentContainer()
    {
        // initialise instance variables
        rents = new ArrayList<Rent>();
    }
    
    public ArrayList<Rent> rentList()
    {
        return rents;
    }
    public void addRent(Rent rent)
    {
        rents.add(rent);
    }
    
     public boolean deleteRent(long id)
    {
        int index = 0;
        boolean found = false;
        Rent rent = null;
        
        while(index < rents.size() && !found)
        {
            rent = rents.get(index);
            
            if(rent.getId() == id)
            {
                found = true;
            }
            else
            {
                index ++;
            }
        }
        
        if(found)
        {
            rents.remove(index);
            return true;
        }
        else
        {
            return false;
        }
    }
    
    public Rent findRent(long id)
    {
        int index = 0;
        boolean found = false;
        Rent rent = null;
        
        while (index < rents.size() && !found)
        {
            rent = rents.get(index);
            
            if(rent.getRentDate().equals(id))
            {
                found = true;
            }
            else
            {
                index ++;
            }
        }
        
        if (found)
        {
            return rents.get(index);
        }
        
        else
        {
            System.out.println("Rent not found");
            return null;
        }
    }
}
